package net.simflow.swf.analyzer.gui.ginfo.display;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;

import net.simflow.swf.analyzer.gui.ConfigDialog;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

public class GraphInfoDisplayConfigDialog extends ConfigDialog {

	private static final String IO = "IO";
	private static final String DEGREE = "Degree Distribution";
	private static final String EXEC = "Execution Result";
	private static final String EXEC_GRAPH = "Graph";
	private static final String EXEC_STATS = "Stats";
	private static final String EXEC_RESULT = "Original Result";
	private static final String BG = "Bipartite Graph";
	private static final String BG_FLOW = "Bipartite Graph Flow Part";
	private static final String BG_SERVICE = "Bipartite Graph Service Part";

	HashMap<String, LinkedHashMap<String, Boolean>> configBinding;
	HashMap<String, Composite> cmpBinding;
	LinkedHashMap<String, ArrayList<String>> tree;

	/**
	 * Create the dialog.
	 * 
	 * @param parent
	 * @param style
	 */
	public GraphInfoDisplayConfigDialog(Shell parent,
			LinkedHashMap<String, Boolean> ioDisConfigPkg,
			LinkedHashMap<String, Boolean> degreeDisConfigPkg,
			LinkedHashMap<String, Boolean> execDisConfigPkgGraph,
			LinkedHashMap<String, Boolean> execDisConfigPkgResult,
			LinkedHashMap<String, Boolean> execDisConfigPkgStats,
			LinkedHashMap<String, Boolean> bgDisConfigPkg,
			LinkedHashMap<String, Boolean> bgFlowDisConfigPkg,
			LinkedHashMap<String, Boolean> bgServiceDisConfigPkg) {
		super(parent, "Exection Result Display Config", new Point(600, 600));

		configBinding = new LinkedHashMap<String, LinkedHashMap<String, Boolean>>();
		configBinding.put(IO, ioDisConfigPkg);
		configBinding.put(DEGREE, degreeDisConfigPkg);
		configBinding.put(EXEC_GRAPH, execDisConfigPkgGraph);
		configBinding.put(EXEC_STATS, execDisConfigPkgStats);
		configBinding.put(EXEC_RESULT, execDisConfigPkgResult);
		configBinding.put(BG, bgDisConfigPkg);
		configBinding.put(BG_FLOW, bgFlowDisConfigPkg);
		configBinding.put(BG_SERVICE, bgServiceDisConfigPkg);

		cmpBinding = new LinkedHashMap<String, Composite>();
		for (String str : configBinding.keySet()) {
			cmpBinding.put(str, new GraphInfoDisplayConfigComposite(parent,
					configBinding.get(str)));
		}

		tree = new LinkedHashMap<String, ArrayList<String>>();
		tree.put(IO, null);
		tree.put(DEGREE, null);
		ArrayList<String> a = new ArrayList<String>();
		a.add(EXEC_GRAPH);
		a.add(EXEC_STATS);
		a.add(EXEC_RESULT);
		tree.put(EXEC, a);
		tree.put(BG, null);
		tree.put(BG_FLOW, null);
		tree.put(BG_SERVICE, null);
	}

	@Override
	protected HashMap<String, Composite> getBinding() {
		return cmpBinding;
	}

	@Override
	protected LinkedHashMap<String, ArrayList<String>> getTree() {
		return tree;
	}

	@Override
	protected void save() {

		for (Entry<String, LinkedHashMap<String, Boolean>> en : configBinding
				.entrySet()) {
			String title = en.getKey();
			LinkedHashMap<String, Boolean> oriMap = en.getValue();
			LinkedHashMap<String, Boolean> newMap = ((GraphInfoDisplayConfigComposite) cmpBinding
					.get(title)).getResult();
			oriMap.clear();
			oriMap.putAll(newMap);
		}

		result = new Object();
	}
}
